﻿using System;
using System.Web.UI.WebControls;
using VipCo.Data;
using VipCo.Entities;

public partial class Controls_DiemDenControl : System.Web.UI.UserControl
{
    private static int idTp = 0;    

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["TP"] != null)
            {
                string sessionTp = Session["TP"].ToString();

                int totalRows = 0;
                string whereClause = "TenThanhPho like N'" + sessionTp + "' and TrangThai = 1";
                TList<ThanhPho> tlistTp = DataRepository.ThanhPhoProvider.GetPaged(whereClause, "Id DESC", 0, 1,
                                                                                   out totalRows);
                idTp = tlistTp[0].Id;
                HienthiDiemden(Pager1.CurrentIndex, idTp);                
            }            
        }
    }
    protected void HienthiDiemden(int pageNo, int idTp)
    {
        int totalRows = 0;
        string whereClause = "TrangThai = 1 and IdThanhPho = " + idTp + " and GETDATE() BETWEEN NgayBatDau AND NgayKetThuc";
        TList<DiaDiem> tlistDiemden = DataRepository.DiaDiemProvider.GetPaged(whereClause, "UuTien DESC, NgayCapNhat DESC, NgayKetThuc ASC", pageNo - 1,
            Pager1.PageSize, out totalRows);
        if (tlistDiemden.Count > 0)
        {
            dlDiemden.DataSource = tlistDiemden;
            dlDiemden.DataBind();
        }

        // Hien thi so luong trang
        TList<DiaDiem> tlistDiemden1 = DataRepository.DiaDiemProvider.GetPaged(whereClause, "Id DESC", 0,
            0, out totalRows);

        if (tlistDiemden1.Count > 0)
        {
            Pager1.ItemCount = tlistDiemden1.Count;
            if (tlistDiemden1.Count < Pager1.PageSize)
            {
                Pager1.Visible = false;
            }
            else
            {
                Pager1.Visible = true;
            }
        }

        
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="Char"></param>
    /// <returns></returns>
    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndex;
        HienthiDiemden(currnetPageIndex, idTp);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="str"></param>
    /// <param name="n"></param>
    /// <returns></returns>
    public string formatString(string str, int n)
    {
        string kq = "";

        if (str.Length > n)
            kq = str.Substring(0, n + 1) + "...";
        else
            kq = str;

        return kq;
    }

    //public string KiemTraTrangThai(int trangthai)
    //{
    //    if (trangthai == 1)
    //        return "<div class=\"xac-thuc\"><span class=\"icon-ok-circle icon-white\"></span><b> Đã được xác thực</b></div>";
    //    return "<div class=\"chua-xac-thuc\"><span class=\"icon-remove-circle icon-white\"></span><b> Chưa được xác thực</b></div>";
    //}
}